package zifuchuan;

import java.util.HashMap;
import java.util.Map;

public class _06两串的字符集相同 {
    //串组成的字符是ASCII
    public static void main(String[] args) {
        Boolean res = check("abcde", "abcde");
        Boolean res1 = check1("abcde", "abcde");
        System.out.println(res);
        System.out.println(res1);
    }

    public static Boolean check(String s1, String s2){
        int[] helper = new int[256];
        //扫描字串s1
        for (int i = 0 ;i < s1.length() ;i++){
            char c = s1.charAt(i);
            if (helper[c] == 0){
                helper[c] = 1;
            }
        }
        //扫描字符串s2
        for (int i = 0 ;i < s2.length();i++){
            char c = s2.charAt(i);
            if (helper[c] == 0){
                return false;
            }
        }
        return true;
    }

    //使用hashMap的方法
    public static Boolean check1(String s1, String s2){
        Map<Character,Integer> map = new HashMap<>();
        //扫描字串s1
        for (int i = 0 ;i < s1.length() ;i++){
            char c = s1.charAt(i);
            if (map.get(c) == null){
                map.put(c,1);
            }
        }
        //扫描字符串s2
        for (int i = 0 ;i < s2.length();i++){
            char c = s2.charAt(i);
            if (map.get(c) == null){
                return false;
            }
        }
        return true;
    }
}
